import time

import openpyxl
import requests
import json

url = 'https://chatgpt4.ceba.ceshiren.com/backend/web/ask'

headers = {
    'authority': 'chatgpt4.ceba.ceshiren.com',
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'zh-CN,zh;q=0.9',
    'content-type': 'application/json',
    'cookie': '_ga=GA1.2.1861164089.1695284726; Hm_lvt_214f62eef822bde113f63fedcab70931=1704279016,1704778435,1706098258; _ga_XP6GNLH30P=GS1.2.1706098258.9.1.1706098825.0.0.0; session=c54f2786-69eb-4eb3-9849-956bd7210605',
    'origin': 'https://chatgpt4.ceba.ceshiren.com',
    'referer': 'https://chatgpt4.ceba.ceshiren.com/',
    'sec-ch-ua': '"Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
}
# 打开 Excel 文件
workbook = openpyxl.load_workbook('abc.xlsx')
sheet2 = workbook.worksheets[1]  # 第二个 tab

i = 1

while(i < 112):
    question = sheet2.cell(row=i, column=1).value
    data = {
        'question': question,
        'stream': True
    }

    # while True:
    #     response = requests.post(url, headers=headers, data=json.dumps(data))
    #     response_data = response.json()
    #     if response_data['code'] == "0":
    #         print("Response code is 0. Stopping the loop.")
    #         break
    #     else:
    #         print("Response code is not 0. Continuing the loop.")
    #         time.sleep(3)
    #     print(response_data)

    mess = "1. 由于车辆右后轮的压推杆问题，导致车身无法精确定位。\n2. 车辆的定位不准，可能是由于右后轮压推杆出了故障。\n3. 右后轮压推杆的故障，似乎扰乱了车辆的精准定位。\n4. 车辆右后轮的压推杆有问题，造成车身定位不准确。\n5. 由于车辆右后轮压推杆的问题，结果在车身定位上表现出来。\n6. 由于车辆右后轮的压推杆问题，导致车身无法精确定位。\n7. 车辆的定位不准，可能是由于右后轮压推杆出了故障。\n8. 右后轮压推杆的故障，似乎扰乱了车辆的精准定位。\n9. 车辆右后轮的压推杆有问题，造成车身定位不准确。\n10. 由于车辆右后轮压推杆的问题，结果在车身定位上表现出来。"

    messages = mess.split('\n')
    # 提取前5个序号的文本
    texts = [message.split('. ')[1] for message in messages[:10]]

    for text in texts:
        sheet2.cell(row=i+1, column=1, value=text)
        i = i + 1
        print(i)
    i = i + 1

    # 保存 Excel 文件
workbook.save('abc.xlsx')
print()


